package com.xuhao.examai.common;

import lombok.Data;
import java.io.Serializable;
import java.util.List;

@Data
public class ResultVO<T> implements Serializable {
	private Integer code;
	private String message;
	private T data;
	private Long timestamp;

	public ResultVO() {
		this.timestamp = System.currentTimeMillis();
	}

	public static <T> ResultVO<T> success(T data) {
		ResultVO<T> result = new ResultVO<>();
		result.setCode(200);
		result.setMessage("success");
		result.setData(data);
		return result;
	}

	public static <T> ResultVO<T> success() {
		return success(null);
	}

	public static <T> ResultVO<T> error(Integer code, String message) {
		ResultVO<T> result = new ResultVO<>();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}

	public static <T> ResultVO<T> error(String message) {
		return error(500, message);
	}

	public static <T> ResultVO<T> unauthorized(String message) {
		return error(401, message);
	}

	public static <T> ResultVO<T> forbidden(String message) {
		return error(403, message);
	}

	public static <T> ResultVO<T> notFound(String message) {
		return error(404, message);
	}

	public static <T> ResultVO<T> badRequest(String message) {
		return error(400, message);
	}
}
